﻿package mortal.game.view.common.tooltip.tooltips
{
    import Message.DB.Tables.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.tooltip.tooltips.base.*;
    import mortal.game.view.mainUI.roleAvatar.*;

    public class ToolTipBuff extends ToolTipScaleBg
    {
        private var _buffDescTxt:GTextFiled;
        private var _leftTime:SecTimerView;
        private var _buffExTxt:GTextFiled;
        private var _buffData:BuffData;

        public function ToolTipBuff()
        {
            this.createChildren();
            return;
        }// end function

        public function createChildren() : void
        {
            var _loc_1:GTextFormat = null;
            setBg(ImagesConst.ToolTipBg);
            _loc_1 = GlobalStyle.textFormatBai;
            this._buffDescTxt = new GTextFiled();
            this._buffDescTxt.multiline = true;
            this._buffDescTxt.autoSize = TextFieldAutoSize.LEFT;
            this._buffDescTxt.defaultTextFormat = _loc_1;
            contentContainer2D.addChild(this._buffDescTxt);
            this._leftTime = new SecTimerView();
            this._leftTime.width = 35;
            this._leftTime.autoSize = TextFieldAutoSize.LEFT;
            this._leftTime.mouseEnabled = false;
            this._leftTime.defaultTextFormat = GlobalStyle.textFormatHuang2;
            this._leftTime.filters = [FilterConst.glowFilter];
            this._leftTime.setParse(Language.getString(30055));
            this._leftTime.y = 40;
            contentContainer2D.addChild(this._leftTime);
            this._buffExTxt = UIFactory.gTextField("", 0, 0, 220, 20, null, _loc_1);
            this.addEventListener(Event.REMOVED_FROM_STAGE, this.removeEvent);
            return;
        }// end function

        private function removeEvent(event:Event) : void
        {
            this._buffData = null;
            this._leftTime.stop();
            this._leftTime.removeEventListener(EventName.SecViewTimeChange, this.onSecViewTimeChangeHandler);
            return;
        }// end function

        private function addEvent() : void
        {
            this._leftTime.addEventListener(EventName.SecViewTimeChange, this.onSecViewTimeChangeHandler);
            return;
        }// end function

        private function onSecViewTimeChangeHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as int;
            if (_loc_2 == 0)
            {
                this._leftTime.stop();
                DisplayUtil.removeMe(this._leftTime);
            }
            else
            {
                if (this._leftTime.parent == null)
                {
                    contentContainer2D.addChild(this._leftTime);
                }
                if (_loc_2 > 3600)
                {
                    this._leftTime.setParse(Language.getString(30055));
                }
                else
                {
                    this._leftTime.setParse(Language.getString(30056));
                }
            }
            return;
        }// end function

        override public function set data(param1) : void
        {
            this._buffData = param1 as BuffData;
            this.updateLeftTime();
            this.resort();
            this.addEvent();
            super.data = param1;
            return;
        }// end function

        private function updateLeftTime() : void
        {
            var _loc_1:int = 0;
            var _loc_2:TBuff = null;
            var _loc_3:Date = null;
            var _loc_4:Date = null;
            if (this._buffData && this._buffData.sbuff && this._buffData.tbuff)
            {
                _loc_2 = this._buffData.tbuff;
                if (_loc_2.lastTime != -1)
                {
                    _loc_3 = this._buffData.sbuff.endDt;
                    _loc_4 = ClockManager.instance.nowDate;
                    _loc_1 = (_loc_3.time - _loc_4.time) * 0.001;
                    if (_loc_1 > 3600)
                    {
                        this._leftTime.setParse(Language.getString(30055));
                    }
                    else
                    {
                        this._leftTime.setParse(Language.getString(30056));
                    }
                    contentContainer2D.addChild(this._leftTime);
                    this._leftTime.setLeftTime(_loc_1);
                    return;
                }
            }
            this._leftTime.stop();
            DisplayUtil.removeMe(this._leftTime);
            return;
        }// end function

        private function resort() : void
        {
            this.updateBuffDescText();
            this.updateBuffExTxt();
            this._leftTime.y = this._buffDescTxt.height + this._buffDescTxt.y;
            this._buffExTxt.y = this._leftTime.parent ? (this._leftTime.height + this._leftTime.y) : (this._buffDescTxt.height + this._buffDescTxt.y);
            return;
        }// end function

        private function updateBuffDescText() : void
        {
            var _loc_2:BuffData = null;
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_1:String = "";
            if (this._buffData.iconGroupList)
            {
                _loc_3 = this._buffData.iconGroupList.length;
                while (_loc_4 < _loc_3)
                {
                    
                    _loc_2 = this._buffData.iconGroupList[_loc_4];
                    if (_loc_2)
                    {
                        if (_loc_3 > 1)
                        {
                            _loc_1 = _loc_1 + ("<font color=\'#1ccc31\'>" + _loc_2.tbuff.name + " : </font>" + _loc_2.tbuff.description + "\n");
                        }
                        else
                        {
                            _loc_1 = "<font color=\'#1ccc31\'>" + this._buffData.tbuff.name + " : </font>\n" + _loc_2.tbuff.description;
                        }
                    }
                    _loc_4++;
                }
            }
            else
            {
                _loc_1 = "<font color=\'#1ccc31\'>" + this._buffData.tbuff.name + " : </font>\n" + this._buffData.tbuff.description;
            }
            this._buffDescTxt.htmlText = _loc_1;
            _scaleBg.width = this._buffDescTxt.width;
            return;
        }// end function

        private function updateBuffExTxt() : void
        {
            if (this._buffData.tbuff.descriptionEx && this._buffData.sbuff)
            {
                contentContainer2D.addChild(this._buffExTxt);
                this._buffExTxt.htmlText = this._buffData.tbuff.descriptionEx.replace("{0}", this._buffData.sbuff.value);
            }
            else
            {
                DisplayUtil.removeMe(this._buffExTxt);
            }
            return;
        }// end function

        public function get buffData() : BuffData
        {
            return this._buffData;
        }// end function

        public function set buffData(param1:BuffData) : void
        {
            this._buffData = param1;
            return;
        }// end function

    }
}
